using System;
using System.ComponentModel;
using System.Diagnostics;
using PostSharp.Laos;

namespace AOP
{
#if !SILVERLIGHT
    [Serializable]
#endif
    public class OnPropertySetSubAspect : OnMethodBoundaryAspect
    {
        readonly string _propertyName;
        
        public OnPropertySetSubAspect() {}

        public OnPropertySetSubAspect(string propertyName)
        {
            _propertyName = propertyName;
        }

        public override void OnSuccess(MethodExecutionEventArgs eventArgs)
        {
            // TODO: Postsharp 2.0
            var m = eventArgs.Instance.GetType().GetMethod("OnPropertyChanged");

            m.Invoke(eventArgs.Instance, new[] {_propertyName});
        }
    }
}